package com.wit.WEB.service.impl;

import com.wit.WEB.entity.User;
import com.wit.WEB.mapper.UserMapper;
import com.wit.WEB.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: WEB
 * @description: UserService
 * @author: KingTeng
 * @create: 2022-02-23 20:14
 **/
@Service
public class UserServiceimpl implements UserService {
    private UserMapper userMapper;
    @Autowired
    private void  setUserMapper(UserMapper userMapper){
        this.userMapper=userMapper;
    }
    @Override
    public User selectByAcAndPW(String account, String pwd) {
        return userMapper.selectByAcAndPW(account, pwd);
    }

    @Override
    public boolean isExist(String account) {
        List<User> users=userMapper.selectByAccount(account);
        if(users.isEmpty()){
            return false;
        }
        return true;
    }

    @Override
    public int insertUser(String account, String pwd) {
        User user=new User();
        user.setAccount(account);
        user.setPwd(pwd);
        user.setPower(0);
        userMapper.insert(user);
        return 1;
    }

    @Override
    public int insertUserStand(String account, String pwd) {
        User user=new User();
        user.setAccount(account);
        user.setPwd(pwd);
        user.setPower(2);
        userMapper.insert(user);
        return 1;
    }

    @Override
    public void deleteByID(String uid) {
        userMapper.deleteByPrimaryKey(Integer.parseInt(uid));
    }

    @Override
    public void UpdateUser(User user) {
        userMapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public User selectByPrimary(Integer uid) {
        return userMapper.selectByPrimaryKey(uid);
    }
}
